<html>
<head>
<title>Welcome to AJAX</title>

<script type="text/javascript">
	var xmlHttp = null;
	window.onload = function() {
		loadXmlHttp();
	}

	function loadXmlHttp() {
		if (window.XMLHttpRequest) { // IE7, Mozilla, Safari, Opera
			xmlHttp = new XMLHttpRequest();
			alert("get XMLHttpRequest success");
		} else if (window.ActiveXObject) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE 5.x, 6
			} catch (e) {
			}
		}
	}

	function sendRequest(url) {
		if (xmlHttp) {
			xmlHttp.open("GET", url, true); // true = async
			xmlHttp.onreadystatechange = onCallback;
			xmlHttp.send(null);
		}
	}

	function onCallback() {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				var div = document.getElementById("result");
				div.innerHTML = div.innerHTML + xmlHttp.responseText;
				alert(xmlHttp.responseText);
			} else {
				alert("Error " + xmlHttp.status);
			}
		}
	}
</script>

</head>
<body>
<h2>Yinangit</h2>
	<div id="result">
	</div>
<button type="button" onclick="sendRequest('sleep.php')">Click to call</button>
</body>

</html>